package de.codi.xtest;

import de.unima.alcomox.ExtractionProblem;
import de.unima.alcomox.exceptions.AlcomoException;
import de.unima.alcomox.mapping.Characteristic;
import de.unima.alcomox.mapping.Mapping;
import de.unima.alcomox.ontology.LocalOntology;


/**
* 
* Shows how the ALCOMO system can be used to compute 
* an optimal solution with complete reasoning. Will
* later on be inlcuded (probably) as final step of the
* whole process.
*
*/
public class AlcomoExample {
	

	public static void main(String[] args) throws AlcomoException {
	
		// load the two ontologies that have been matched
		LocalOntology sourceOnt = new LocalOntology("res/examples/cmt.owl");
		LocalOntology targetOnt = new LocalOntology("res/examples/ekaw.owl");
		
		// load the alignment that has been generated by a matcher
		Mapping mapping = new Mapping("res/examples/cmt-ekaw/AgrMaker.rdf");
		Mapping reference = new Mapping("res/examples/ref-cmt-ekaw.rdf");
		

		
		// prepare the settings of the extraction problem
		// 
		// available methods = available types of diagnosis:
		// ExtractionProblem.METHOD_OPTIMAL (global) or ExtractionProblem.METHOD_GREEDY (local)
		// 
		// available reasoning settings:
		// ExtractionProblem.REASONING_COMPLETE - efficient and complete variant of the algoritms
		// ExtractionProblem.REASONING_BRUTEFORCE - brute force variant of the algoritms
		// ExtractionProblem.REASONING_EFFICIENT - incomplete, only pattern based reasoning
		// 
		// It is recommended not to change ExtractionProblem.ENTITIES_CONCEPTSPROPERTIES
		// to a different value (current setting takes concepts and properties into account)
		//
		ExtractionProblem ep = new ExtractionProblem(
				ExtractionProblem.ENTITIES_CONCEPTSPROPERTIES,
				ExtractionProblem.METHOD_OPTIMAL,
				ExtractionProblem.REASONING_COMPLETE
		);
		
		// bind the ontologies and the mapping to the extraction problem
		ep.bindSourceOntology(sourceOnt);
		ep.bindTargetOntology(targetOnt);
		ep.bindMapping(mapping);
		
		// solve the problem
		ep.solve();
		
		// display the results
		System.out.println("Subalignment that has been discarded during debugging (= the diagnosis):");
		System.out.println(ep.getDiscardedMapping());
		System.out.println("Debugged alignment:");
		System.out.println(ep.getExtractedMapping());
		
		// compute precision and recall
		Characteristic before = new Characteristic(mapping, reference);
		Characteristic after = new Characteristic(ep.getExtractedMapping(), reference);
		
		System.out.println();
		System.out.println("Before debugging:\n" + before);
		System.out.println("After debugging: \n" + after);
		
		
	}	

	
	
}
